import {Body, Controller, Get, Post, Query, Request, RequestMapping} from "@nestjs/common";
import {ApiOperation, ApiTags} from "@nestjs/swagger";
import {RecommendRealTimeService} from "./recommendRealTime.service";
import {JwtPayload} from "../../common/types/jwt.type";
import {RecommendOfflineService} from "./recommendOffline.service";
import {UserActions} from "../../common/enums/userActions";
import {UserProfileDto} from "./recommend.dto";

@ApiTags("推荐模块")
@Controller("recommend")
export class RecommendController {

    constructor(
        private readonly recommendRealTimeService: RecommendRealTimeService,
        private readonly recommendOfflineService: RecommendOfflineService
    ) {
    }

    @Get()
    @ApiOperation({summary: "向用户推荐图书数据"})
    async getRecommendBookListComprehensive(
        @Request() req,
        @Query("size") size: number
    ) {
        const user: JwtPayload = req.user
        return await this.recommendRealTimeService.getRecommendBookListComprehensive(user.userId, size,{})
    }

    @Post()
    @ApiOperation({summary: "向用户推荐图书数据(当用户第一次登录时，调用这个接口)"})
    async getRecommendBookListComprehensiveByData(
        @Request() req,
        @Query("size") size: number,
        @Body() body: UserProfileDto
    ) {
        const user: JwtPayload = req.user
        return await this.recommendRealTimeService.getRecommendBookListComprehensive(user.userId, size, body)
    }

    @Get("userProfile")
    @ApiOperation({summary: "获取用户画像数据"})
    async getUserProfile(
        @Request() req,
        @Query("size") size: number
    ) {
        const {userId}: JwtPayload = req.user
        return await this.recommendRealTimeService.getUserProfile(userId)
    }

    @Get("hot")
    @ApiOperation({summary: "获取图书热度排行榜"})
    async getBookHotList(
        @Query("size") size: number
    ) {
        return await this.recommendOfflineService.getHotBook(size)
    }

    @Get("history")
    @ApiOperation({summary: "获取用户的历史阅读书籍"})
    async getReadBookListHistory(
        @Request() req,
        @Query("size") size: number
    ) {
        const {userId}: JwtPayload = req.user
        const result = await this.recommendRealTimeService.getBookListByActionOrderByTime(userId,UserActions.HAS_READ)
        return result.slice(0,size)
    }

    @Get("book")
    @ApiOperation({summary: "根据指定书籍Id进行推荐，按评分排序"})
    async getBookListByLabel(
        @Query("size") size: number,
        @Query("bookId") bookId: string
    ) {
        return await this.recommendRealTimeService.getRecommendBookListByBookId(bookId, size)
    }


    // @Get("label")
    // @ApiOperation({summary: "查询具有指定标签的书籍，按评分排序"})
    // async getBookListByLabel(
    //     @Query("size") size: number,
    //     @Query("labels") labels: string
    // ) {
    //     const labelList = labels.split(",")
    //     return await this.recommendRealTimeService.getBookListByLabels(labelList, size)
    // }

    // @Get("author")
    // @ApiOperation({summary: "向用户推荐图书数据(根据作者)"})
    // async getRecommendBookListByAuthor(
    //     @Request() req,
    //     @Query("size") size: number
    // ) {
    //     const user: JwtPayload = req.user
    //     return await this.recommendRealTimeService.getRecommendBookListByAuthor(user.userId, size)
    // }
    //
    // @Get("type")
    // @ApiOperation({summary: "向用户推荐图书数据(根据分类)"})
    // async getRecommendBookListByType(
    //     @Request() req,
    //     @Query("size") size: number
    // ) {
    //     const user: JwtPayload = req.user
    //     return await this.recommendRealTimeService.getRecommendBookListByType(user.userId, size)
    // }

    // @Get("label")
    // @ApiOperation({summary: "向用户推荐图书数据(根据标签)"})
    // async getRecommendBookListByLabel(
    //     @Request() req,
    //     @Query("size") size: number
    // ) {
    //     const user: JwtPayload = req.user
    //     return await this.recommendRealTimeService.getRecommendBookListByLabel(user.userId, size)
    // }

    // @Get("read")
    // @ApiOperation({summary: "获取用户读过的图书列表"})
    // async getReadBookList(
    //     @Request() req
    // ) {
    //     const user: JwtPayload = req.user
    //     return await this.recommendRealTimeService.getReadBookListOrderByTime(user.userId)
    // }


}
